package com.liang.service.impl;

import com.liang.dao.UserMapper;
import com.liang.pojo.User;
import com.liang.service.UserService;
import com.liang.utils.MybatisUtils;
import com.liang.utils.Utilgetter;
import org.apache.ibatis.session.SqlSession;

import java.math.BigInteger;
import java.util.List;

public class UserServiceImpl implements UserService {
    static SqlSession sqlSessionAuto =null;
    static SqlSession sqlSession=null;

    //插入User表指定的字段
    public String updateUser(BigInteger userId,BigInteger[] movieType) {
        sqlSessionAuto = MybatisUtils.getSqlSessionAuto();
        String msg="没有信息";
        UserMapper mapper = sqlSessionAuto.getMapper(UserMapper.class);
        User user = new User();
        for(int i=0;i<movieType.length;i++){
            Utilgetter.getTypeMethod(movieType[i].intValue(),user);
        }
        user.setUserId(userId);
        int i = mapper.updateUser(user);
        sqlSessionAuto.close();
        if (i>0){
            msg="更新成功";
        }
        System.out.println(msg);
        return msg;
    }
    //根据userId得到user对象
    public User getUser(int userId) {
        sqlSessionAuto=MybatisUtils.getSqlSession();
        User user = new User();
        UserMapper mapper = sqlSessionAuto.getMapper(UserMapper.class);
        user= mapper.getUser(userId);
        sqlSessionAuto.close();
        return user;
    }
    //查询user表得到user对象集合
    public List<User> getUserList() {
        List<User> userList=null;
        sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        userList = mapper.getUserList();
        sqlSession.close();
        return userList;
    }
}
